package com.hhss.qishi.controller;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.hhss.qishi.config.pagehelper.PageVO;
import com.hhss.qishi.entity.Article;
import com.hhss.qishi.entity.Picture;
import com.hhss.qishi.service.PictureService;
import com.hhss.qishi.utils.ConvertPageUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @Auther: zcc
 * @Date: 19-6-20 14:42
 * @Description: 图片controller
 */
@RestController
@RequestMapping("pictures")
public class PictureController {

    @Autowired
    private PictureService pictureService;

    /**
     * 获取图片列表，分页
     * @param picture
     * @return
     */
    @RequestMapping(value = "/", method = RequestMethod.GET)
    public Map<String, Object> getList(Picture picture){
        Page<Article> page= PageHelper.startPage(picture.getPage(), picture.getLimit());
        pictureService.getList(picture);
        PageVO<Article> vo = PageVO.build(page);
        return ConvertPageUtil.Convert(vo);
    }

    /**
     * 新增图片
     * @param picture
     * @return
     */
    @RequestMapping(value = "/", method = RequestMethod.POST)
    public int add(Picture picture){
        return pictureService.add(picture);
    }

    /**
     * 根据id获取图片信息
     * @return
     */
    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    public Picture getById(@PathVariable Long id){
        return pictureService.getById(id);
    }

    /**
     * 修改图片信息,根据id
     * @param picture
     * @return
     */
    @RequestMapping(value = "/", method = RequestMethod.PUT)
    public int modify(Picture picture){
        return pictureService.updateById(picture);
    }
}
